<template>
	<view class="content">
		<view class="catList">
			<catLabel dataType="text" text="姓名"  v-model="realName"/>
			<catLabel dataType="text" inputType="number" text="手机"  v-model="phone"/>
			<catLabel dataType="textarea" inputType="textarea" text="内容" v-model="desc"/>
		</view>
		<button class="submit" @click="sendBusinessMessage">保存</button>
	</view>
</template>

<script>
	import catLabel from "@/components/cat-label/cat-label.vue"
	export default {
		data(){
			return{
				realName: '',
				phone: '',
				desc: '',
				personId: '',
				companyId: '',
			}
		},
		components:{
			catLabel
		},
		onLoad(query){
			if(query.personId){
				this.personId = query.personId
			}
			if(query.companyId){
				this.companyId = query.companyId
			}
		},
		methods:{
			async sendBusinessMessage(){
				let params = {
					user_token: uni.getStorageSync('userToken'),
					company_id: this.companyId,
					character_id: this.personId,
					content: this.desc,
					realname: this.realName,
					phone: this.phone
				}
				const res = await this.$api.sendBusinessMessage(params);
				if(res.data.level == 'success'){
					uni.showToast({
						icon:'success',
						title:res.data.message
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},2000)
				}else{
					uni.showToast({
						icon:'none',
						title:res.data.message
					})
				}
			}
		}
	}
</script>

<style>
	.catList{
		padding-bottom:100rpx;
	}
	.submit{
		position: fixed;
		bottom:0rpx;
		width: 100%;
		background: linear-gradient(-135deg, #57D1E2 0%, #37AED6 100%);
		color:#fff
	}
</style>
